package cn.hh.wechatkit.component;

import cn.hh.wechatkit.api.token.WxAPI_Access_GetOpenId_Api;
import cn.hh.wechatkit.exception.Wx_Exception_GetTokenFailed;
import cn.hh.wechatkit.exception.Wx_Exception_InvalidJsonParse;
import cn.hh.wechatkit.exception.Wx_Exception_InvalidResponse;
import cn.hh.wechatkit.helper.CacheHelper;
import cn.hh.wechatkit.param.WxParam;
import cn.hh.wechatkit.pojo.token.*;

import java.io.IOException;

/**
 * Created this one by HMH on 2017/5/23.
 * Token管理组件
 */
public class WxCom_Token {

    //获取access_token
    public WxToken_AccessToken getAccessToken() throws Wx_Exception_GetTokenFailed, IOException, Wx_Exception_InvalidResponse, Wx_Exception_InvalidJsonParse {
        return CacheHelper.getAccessToken();
    }

    //获取小程序access_token
    public WxToken_AccessToken getAppAccessToken() throws Wx_Exception_GetTokenFailed, IOException, Wx_Exception_InvalidResponse, Wx_Exception_InvalidJsonParse {
        return CacheHelper.getAppAccessToken();
    }


    public WxToken_ApiTicketToken getApiTicketToken() throws Wx_Exception_GetTokenFailed, IOException, Wx_Exception_InvalidResponse, Wx_Exception_InvalidJsonParse {
        return CacheHelper.getApiTicketToken();
    }

    public WxToken_AuthoAccessToken getAuthoAccessToken(String code) throws Wx_Exception_GetTokenFailed, IOException, Wx_Exception_InvalidResponse, Wx_Exception_InvalidJsonParse {
        return CacheHelper.getAuthoAccessToken(code);
    }

    public WxToken_JsApiToken getJsApiToken() throws Wx_Exception_GetTokenFailed, Wx_Exception_InvalidResponse, Wx_Exception_InvalidJsonParse, IOException {
        return CacheHelper.getJsApiToken();
    }

    public WxApp_OpenIdSession getOpenIdSession(String code) {
        return WxAPI_Access_GetOpenId_Api.getOpenIdSession(WxParam.miniAppId, WxParam.miniAppSecret,code);
    }

}
